import 'dart:math';
import 'dart:ui';

extension ScreenFitDouble on double {
  get rpx {
    final width = window.physicalSize.width;
    final height = window.physicalSize.height;

    final ratio = window.devicePixelRatio;
    return this * ((min(width, height) / ratio) / 375);
  }

  get px {
    final width = window.physicalSize.width;
    final height = window.physicalSize.height;

    final ratio = window.devicePixelRatio;
    return this / 2 * ((min(width, height) / ratio) / 375);
  }
}

extension ScreenFitInt on int {
  get rpx {
    final width = window.physicalSize.width;
    final height = window.physicalSize.height;

    final ratio = window.devicePixelRatio;
    return this * ((min(width, height) / ratio) / 375);
  }

  get px {
    final width = window.physicalSize.width;
    final height = window.physicalSize.height;

    final ratio = window.devicePixelRatio;
    return this / 2 * ((min(width, height) / ratio) / 375);
  }
}

final kScreenHeight = window.physicalSize.height / window.devicePixelRatio;
final kScreenWidth = window.physicalSize.width / window.devicePixelRatio;

final kSafeTop = window.padding.top / window.devicePixelRatio;
final kSafeBottom = window.padding.bottom / window.devicePixelRatio;
final safeTop = window.padding.top / window.devicePixelRatio;
final safeBottom = window.padding.bottom / window.devicePixelRatio;

final kNavHeight = 56 + max(kSafeTop, 20);

toFit(num) {
  final width = window.physicalSize.width;
  final height = window.physicalSize.height;
  final ratio = window.devicePixelRatio;
  return num * ((min(width, height) / ratio) / 375);
}
